package com.lintf.nacos;

import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.netflix.loadbalancer.IRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author lin tingfeng
 * @ system Mac
 * @ data 2025/3/20 16:25
 * @ package_name com.lintf.nacos
 * @ project_name Default (Template) Project
 * @ desc
 */
@SpringBootApplication
public class SpringNacosCloud2313Main {

    @Bean
    // 开启负载均衡：RestTemplate 会自动在请求头中加入服务名
    // 如果不加会导致找不到服务的错误
    @LoadBalanced // 这个负载均衡是Ribbon的功能 默认是Ribbon
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 采用Nacos的负载均衡规则
    @Bean
    public IRule ribbonRule() {
        return new NacosRule();
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringNacosCloud2313Main.class, args);
    }
}